#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "support.h"
#include "find.h"
#include "file.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
        g_object_set_data_full (G_OBJECT (component), name, \
                gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
        g_object_set_data (G_OBJECT (component), name, widget)

        
GtkWidget*
create_window_find_info (struct findinfo_struct *findinfo,struct clist_struct *clist)
{
  GtkWidget *window;
  GtkWidget *label_name;
  GtkWidget *label_mail;
  GtkWidget *entry_name;
  GtkWidget *entry_mail;
  GtkWidget *button_help;
  GtkWidget *label_help;  
  GtkWidget *button_cancel;
  GtkWidget *label_cancel;
  GtkWidget *button_ok;
  GtkWidget *label_ok;
  
  GtkWidget *table_main;
  GtkWidget *alignment7;
  GtkWidget *hbox11;
  GtkWidget *image8;
  GtkWidget *hbox10;
  GtkWidget *alignment8;
  GtkWidget *hbox12;
  GtkWidget *image9;
  GtkWidget *fixed4;
  GtkWidget *alignment9;
  GtkWidget *hbox13;
  GtkWidget *image10;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), _("\346\237\245\346\211\276\344\277\241\346\201\257"));
    gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_modal (GTK_WINDOW (window), TRUE);
  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  gtk_window_set_icon_name (GTK_WINDOW (window), "gtk-find");
  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);

  table_main = gtk_table_new (3, 2, FALSE);
  gtk_widget_show (table_main);
  gtk_container_add (GTK_CONTAINER (window), table_main);
  gtk_widget_set_size_request (table_main, 279, -1);
  gtk_container_set_border_width (GTK_CONTAINER (table_main), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table_main), 18);
  gtk_table_set_col_spacings (GTK_TABLE (table_main), 10);

  label_name = gtk_label_new (_("\345\247\223\345\220\215\357\274\232"));
  gtk_widget_show (label_name);
  gtk_table_attach (GTK_TABLE (table_main), label_name, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label_name), 0, 0.5);
  gtk_misc_set_padding (GTK_MISC (label_name), 10, 0);

  label_mail = gtk_label_new (_("\351\202\256\347\256\261\357\274\232"));
  gtk_widget_show (label_mail);
  gtk_table_attach (GTK_TABLE (table_main), label_mail, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label_mail), 0, 0.5);
  gtk_misc_set_padding (GTK_MISC (label_mail), 10, 0);

  entry_name = gtk_entry_new ();
  gtk_widget_show (entry_name);
  gtk_table_attach (GTK_TABLE (table_main), entry_name, 1, 2, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_entry_set_invisible_char (GTK_ENTRY (entry_name), 9679);

  entry_mail = gtk_entry_new ();
  gtk_widget_show (entry_mail);
  gtk_table_attach (GTK_TABLE (table_main), entry_mail, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_entry_set_invisible_char (GTK_ENTRY (entry_mail), 9679);

  button_help = gtk_button_new ();
  gtk_widget_show (button_help);
  gtk_table_attach (GTK_TABLE (table_main), button_help, 0, 1, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (button_help, 70, -1);

  alignment7 = gtk_alignment_new (0.5, 0.5, 0, 0);
  gtk_widget_show (alignment7);
  gtk_container_add (GTK_CONTAINER (button_help), alignment7);

  hbox11 = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox11);
  gtk_container_add (GTK_CONTAINER (alignment7), hbox11);

  image8 = gtk_image_new_from_stock ("gtk-help", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image8);
  gtk_box_pack_start (GTK_BOX (hbox11), image8, FALSE, FALSE, 0);

  label_help = gtk_label_new_with_mnemonic (_("\345\270\256\345\212\251"));
  gtk_widget_show (label_help);
  gtk_box_pack_start (GTK_BOX (hbox11), label_help, FALSE, FALSE, 0);

  hbox10 = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (hbox10);
  gtk_table_attach (GTK_TABLE (table_main), hbox10, 1, 2, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);

  button_cancel = gtk_button_new ();
  gtk_widget_show (button_cancel);
  gtk_box_pack_start (GTK_BOX (hbox10), button_cancel, FALSE, FALSE, 0);
  gtk_widget_set_size_request (button_cancel, 85, -1);

  alignment8 = gtk_alignment_new (0.5, 0.5, 0, 0);
  gtk_widget_show (alignment8);
  gtk_container_add (GTK_CONTAINER (button_cancel), alignment8);

  hbox12 = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox12);
  gtk_container_add (GTK_CONTAINER (alignment8), hbox12);

  image9 = gtk_image_new_from_stock ("gtk-cancel", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image9);
  gtk_box_pack_start (GTK_BOX (hbox12), image9, FALSE, FALSE, 0);

  label_cancel = gtk_label_new_with_mnemonic (_("\345\217\226\346\266\210"));
  gtk_widget_show (label_cancel);
  gtk_box_pack_start (GTK_BOX (hbox12), label_cancel, FALSE, FALSE, 0);

  fixed4 = gtk_fixed_new ();
  gtk_widget_show (fixed4);
  gtk_box_pack_start (GTK_BOX (hbox10), fixed4, TRUE, TRUE, 0);

  button_ok = gtk_button_new ();
  gtk_widget_show (button_ok);
  gtk_box_pack_start (GTK_BOX (hbox10), button_ok, FALSE, FALSE, 0);
  gtk_widget_set_size_request (button_ok, 85, -1);

  alignment9 = gtk_alignment_new (0.5, 0.5, 0, 0);
  gtk_widget_show (alignment9);
  gtk_container_add (GTK_CONTAINER (button_ok), alignment9);

  hbox13 = gtk_hbox_new (FALSE, 2);
  gtk_widget_show (hbox13);
  gtk_container_add (GTK_CONTAINER (alignment9), hbox13);

  image10 = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON);
  gtk_widget_show (image10);
  gtk_box_pack_start (GTK_BOX (hbox13), image10, FALSE, FALSE, 0);

  label_ok = gtk_label_new_with_mnemonic (_("\347\241\256\345\256\232"));
  gtk_widget_show (label_ok);
  gtk_box_pack_start (GTK_BOX (hbox13), label_ok, FALSE, FALSE, 0);

  g_signal_connect ((gpointer) window, "destroy",
                    G_CALLBACK (on_window_find_info_destroy),
                    NULL);
  g_signal_connect ((gpointer) button_help, "clicked",
                    G_CALLBACK (on_button_find_info_help_clicked),
                    (gpointer)window);
  g_signal_connect ((gpointer) button_cancel, "clicked",
                    G_CALLBACK (on_button_find_info_cancel_clicked),
                    (gpointer)window);
  g_signal_connect ((gpointer) button_ok, "clicked",
                    G_CALLBACK (on_button_find_info_ok_clicked),
                    (gpointer)findinfo);

  /* Store pointers to all widgets, for use by lookup_widget(). */
  GLADE_HOOKUP_OBJECT_NO_REF (window, window, "window");
  GLADE_HOOKUP_OBJECT (window, table_main, "table_main");
  GLADE_HOOKUP_OBJECT (window, label_name, "label_name");
  GLADE_HOOKUP_OBJECT (window, label_mail, "label_mail");
  GLADE_HOOKUP_OBJECT (window, entry_name, "entry_name");
  GLADE_HOOKUP_OBJECT (window, entry_mail, "entry_mail");
  GLADE_HOOKUP_OBJECT (window, button_help, "button_help");
  GLADE_HOOKUP_OBJECT (window, alignment7, "alignment7");
  GLADE_HOOKUP_OBJECT (window, hbox11, "hbox11");
  GLADE_HOOKUP_OBJECT (window, image8, "image8");
  GLADE_HOOKUP_OBJECT (window, label_help, "label_help");
  GLADE_HOOKUP_OBJECT (window, hbox10, "hbox10");
  GLADE_HOOKUP_OBJECT (window, button_cancel, "button_cancel");
  GLADE_HOOKUP_OBJECT (window, alignment8, "alignment8");
  GLADE_HOOKUP_OBJECT (window, hbox12, "hbox12");
  GLADE_HOOKUP_OBJECT (window, image9, "image9");
  GLADE_HOOKUP_OBJECT (window, label_cancel, "label_cancel");
  GLADE_HOOKUP_OBJECT (window, fixed4, "fixed4");
  GLADE_HOOKUP_OBJECT (window, button_ok, "button_ok");
  GLADE_HOOKUP_OBJECT (window, alignment9, "alignment9");
  GLADE_HOOKUP_OBJECT (window, hbox13, "hbox13");
  GLADE_HOOKUP_OBJECT (window, image10, "image10");
  GLADE_HOOKUP_OBJECT (window, label_ok, "label_ok");

  findinfo->global_file=&global_file;
  findinfo->clist=clist;
  findinfo->label_name = label_name;
  findinfo->label_mail = label_mail;
  findinfo->entry_name = entry_name;
  findinfo->entry_mail = entry_mail;
  findinfo->button_help = button_help;
  findinfo->label_help = label_help;  
  findinfo->button_cancel = button_cancel;
  findinfo->label_cancel = label_cancel;
  findinfo->button_ok = button_ok;
  findinfo->label_ok = label_ok;
  
  return window;
}
